package com.firewolf.security.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 作者：刘兴
 * 时间:18/11/26
 **/
@Controller
public class UserController {

    @RequestMapping("hello")
    public String hello() {
        String hello = "hello";
        return hello;
    }


    /**
     * @return
     */
    @RequestMapping("login")
    public String login() {
        return "mylogin";
    }

    @RequestMapping("logout")
    public void logout(HttpServletRequest request) {
        try {
            System.out.println("用户退出了");
            request.logout();
        } catch (ServletException e) {
            e.printStackTrace();
        }
    }

    @RequestMapping("add")
    public String toAdd() {
        return "add";
    }



    //设置默认访问的页面
    @RequestMapping("/")
    public String indexPage() {
        return "redirect:/index.jsp";
    }

    @RequestMapping("test")
    @ResponseBody
    public String test(){
        return "test";
    }

}
